with Interfaces.C; use Interfaces.C;
with System;
with SDL_stdinc_h;

package SDL_thread_h is

  --    SDL - Simple DirectMedia Layer
  --    Copyright (C) 1997-2006 Sam Lantinga
  --    This library is free software; you can redistribute it and/or
  --    modify it under the terms of the GNU Lesser General Public
  --    License as published by the Free Software Foundation; either
  --    version 2.1 of the License, or (at your option) any later version.
  --    This library is distributed in the hope that it will be useful,
  --    but WITHOUT ANY WARRANTY; without even the implied warranty of
  --    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  --    Lesser General Public License for more details.
  --    You should have received a copy of the GNU Lesser General Public
  --    License along with this library; if not, write to the Free Software
  --    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  --    Sam Lantinga
  --    slouken@libsdl.org
  -- 

  -- Header for the SDL thread management routines 
  --	These are independent of the other SDL routines.
  -- 

  -- Thread synchronization primitives  
  -- Set up for C function definitions, even when using C++  
  -- The SDL thread structure, defined in SDL_thread.c  
   --  skipped empty struct SDL_Thread

  -- Create a thread  
  --   We compile SDL into a DLL on OS/2. This means, that it's the DLL which
  --   creates a new thread for the calling process with the SDL_CreateThread()
  --   API. There is a problem with this, that only the RTL of the SDL.DLL will
  --   be initialized for those threads, and not the RTL of the calling application!
  --   To solve this, we make a little hack here.
  --   We'll always use the caller's _beginthread() and _endthread() APIs to
  --   start a new thread. This way, if it's the SDL.DLL which uses this API,
  --   then the RTL of SDL.DLL will be used to create the new thread, and if it's
  --   the application, then the RTL of the application will be used.
  --   So, in short:
  --   Always use the _beginthread() and _endthread() of the calling runtime library!
  -- 

   function SDL_CreateThread (fn : access function (arg1 : System.Address) return int; data : System.Address) return System.Address;  -- SDL_thread.h:92:92
   pragma Import (C, SDL_CreateThread, "SDL_CreateThread");

  -- Get the 32-bit thread identifier for the current thread  
   function SDL_ThreadID return SDL_stdinc_h.Uint32;  -- SDL_thread.h:96:49
   pragma Import (C, SDL_ThreadID, "SDL_ThreadID");

  -- Get the 32-bit thread identifier for the specified thread,
  --   equivalent to SDL_ThreadID() if the specified thread is NULL.
  --  

   function SDL_GetThreadID (thread : System.Address) return SDL_stdinc_h.Uint32;  -- SDL_thread.h:101:66
   pragma Import (C, SDL_GetThreadID, "SDL_GetThreadID");

  -- Wait for a thread to finish.
  --   The return code for the thread function is placed in the area
  --   pointed to by 'status', if 'status' is not NULL.
  --  

   procedure SDL_WaitThread (thread : System.Address; status : access int);  -- SDL_thread.h:107:76
   pragma Import (C, SDL_WaitThread, "SDL_WaitThread");

  -- Forcefully kill a thread without worrying about its state  
   procedure SDL_KillThread (thread : System.Address);  -- SDL_thread.h:110:63
   pragma Import (C, SDL_KillThread, "SDL_KillThread");

  -- Ends C function definitions when using C++  
end SDL_thread_h;
